//
//  FriendTableViewCell.m
//  自定义高度
//
//  Created by 逗比小胖！ on 16/2/29.
//  Copyright © 2016年 徐晨. All rights reserved.
//

#import "FriendTableViewCell.h"
#import "Friend.h"
#import "FriendFrame.h"


@interface FriendTableViewCell()
@property(nonatomic,weak)UIImageView *iconView;
@property(nonatomic,weak)UIImageView *picView;
@property(nonatomic,weak)UILabel *nameLab;
@property(nonatomic,weak)UILabel *textLab;
@property(nonatomic,weak)UIButton *recommendBtn;
@property(nonatomic,weak)UIButton *zanBtn;
@property(nonatomic,weak)UIButton *relayBtn;



@end

@implementation FriendTableViewCell

+ (instancetype)friendcellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"friendCell";
    static BOOL isRegist = NO;
    if(isRegist == NO){
        isRegist = YES;
        [tableView registerClass:[self class] forCellReuseIdentifier:ID];
    }
    return [tableView dequeueReusableCellWithIdentifier:ID];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        UIImageView *iconView = [[UIImageView alloc]init];
        self.iconView = iconView;
        [self.contentView addSubview:iconView];
        
        UIImageView *picView = [[UIImageView alloc]init];
        self.picView  = picView;
        [self.contentView addSubview:picView];
        
        UILabel *textLab = [[UILabel alloc]init];
        textLab.font = kText;
        textLab.numberOfLines = 0;
        self.textLab = textLab;
        [self.contentView addSubview:textLab];
        
        UILabel *nameLab = [[UILabel alloc]init];
        nameLab.font = kName;
        self.nameLab = nameLab;
        [self.contentView addSubview:nameLab];
        
        UIButton * btn1 = [[UIButton alloc]init];
        [btn1 setTitle:@"评论" forState:UIControlStateNormal];
        
//        [btn1 addTarget:self action:@selector(recommendBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn1.backgroundColor = [UIColor redColor];
        self.recommendBtn = btn1;
        [self.contentView addSubview:btn1];
        
        UIButton * btn2 = [[UIButton alloc]init];
         btn2.backgroundColor = [UIColor greenColor];
        [btn2 setTitle:@"点赞" forState:UIControlStateNormal];
        self.zanBtn = btn2;
        [self.contentView addSubview:btn2];
        
        UIButton *btn3 = [[UIButton alloc]init];
        
         btn3.backgroundColor = [UIColor blackColor];
        [btn3 setTitle:@"转发" forState:UIControlStateNormal];
        self.relayBtn = btn3;
        [self.contentView addSubview:btn3];
        
        
    }
    return  self;
}

//- (void)recommendBtnClick:(UIButton *)button{
//    [self showFromBtn:button];
//}
//- (void)showFromBtn:(UIButton *)recommendBtn{
//    CGSize screenSize = [UIScreen mainScreen].bounds.size;
//    RecommendView *view = [[RecommendView alloc]initWithFrame:CGRectMake(0, 0, screenSize.width, screenSize.height)];
//    
//    view.delegate = self;
//    CGRect newRect = [recommendBtn convertRect:recommendBtn.bounds toView:self];
//    RecommendViewController *menuTableContro = [[RecommendViewController alloc]init];
//    menuTableContro.tableView.frame = CGRectMake(0, 0, 300, 300);
//    CGFloat menuX = newRect.origin.x + newRect.size.width * 0.5 - menuTableContro.tableView.frame.size.width * 0.5;
//    CGFloat menuY = CGRectGetMaxY(newRect) + 10;
//    
//    CGRect tempRect = menuTableContro.tableView.frame;
//    tempRect.origin.x = menuX;
//    tempRect.origin.y = menuY;
//    menuTableContro.tableView.frame = tempRect;
//    
//    [view setContentContro:menuTableContro];
//    
//    [self addSubview:view];
//
//}
//
//- (void)showMenuView:(RecommendView *)recommendView{
//    self.recommendBtn.selected = !self.recommendBtn.selected;
//}
//- (void)dismissMenuView:(RecommendView *)recommendView{
//    self.recommendBtn.selected = !self.recommendBtn.selected;
//
//}

- (void)setFriendFrame:(FriendFrame *)friendFrame{
    _friendFrame =friendFrame;
    [self setData];
    [self setDataFrame];
    
    
}

- (void)setData{
    Friend *friend = self.friendFrame.friend;
    self.iconView.image = [UIImage imageNamed:friend.icon];
    self.textLab.text = friend.text;
    
    self.nameLab.text = friend.name;
    
    
    if(friend.picture){
        self.picView.hidden = NO;
        self.picView.image = [UIImage imageNamed:friend.picture];
    }else{
        self.picView.hidden = YES;
    }
}

- (void)setDataFrame{
    self.iconView.frame = self.friendFrame.iconImageViewFrame;
    self.picView.frame = self.friendFrame.picImageViewFrame;
    self.nameLab.frame = self.friendFrame.nameLabFrame;
    self.textLab.frame = self.friendFrame.textLabFrame;
    
    self.recommendBtn.frame = self.friendFrame.btn1Frame;
    self.zanBtn.frame = self.friendFrame.btn2Frame;
    self.relayBtn.frame = self.friendFrame.btn3Frame;

    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
